using Godot;

public partial class Environment : WorldEnvironment
{

	private VoxelWorld voxel_world;
	private Node settings;
	public override void _Ready()
	{
		voxel_world = GetNode<VoxelWorld>("../VoxelWorld");
		settings = GetNode<Node>("/root/Settings");
	}

	public override void _Process(double delta)
	{
		Environment.FogEnabled = (bool)settings.Get("fog_enabled");

		var target_distance = Mathf.Clamp(voxel_world.effectiveRenderDistance, 2, voxel_world.RenderDistance - 1) * VoxelWorld.CHUNK_SIZE;
		var rate = delta * 4;
		//Settings.fog_distance = move_toward(Settings.fog_distance, target_distance, rate);
		settings.Set("fog_distance", Mathf.MoveToward((float)settings.Get("fog_distance"), target_distance, rate));
		Environment.FogDensity = 0.5f / (float)settings.Get("fog_distance");
	}

}
